<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>修改</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath }/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js?v=3.3.6"></script>
    
    <!-- 自定义js -->
    <script src="${pageContext.request.contextPath }/js/content.js?v=1.0.0"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="${pageContext.request.contextPath }/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/layer/layer.min.js"></script>
	<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=C75HGmvnjDq1Fer37Mrkw24YfBKyQKI9"></script>
    
	<style>
		input,select{
			 width:168px;
			 height:25px;
			 border:1px solid #ccc;
			 margin-left:24px;
		}
		
		.form-item{
			display:flex;
		}
		.label-text{
		   height: 34px;
		   line-height: 34px;
		   font-weight: normal;
		}
		.addInput{ 
			background-color: #ffffff;
		    background-image: none;
		    border: 1px solid #e5e6e7;
		    border-radius: 1px;
		    color: inherit;
		    display: block;
		    font-size: 14px;
		    padding: 6px 12px;
		    transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
		    height: 34px;
		   line-height: 34px;
		   flex: 1;
		}
		.saveBtn{
			 display: block;
		    margin: 15px auto;
		    width: 120px;
		}
		
	input[type="radio"] + label::before {
	    content: "\a0"; /*不换行空格*/
	    display: inline-block;
	    vertical-align: middle;
	    font-size: 18px;
	    width: 1em;
	    height: 1em;
	    margin-right: .4em;
	    border-radius: 50%;
	    border: 1px solid #01cd78;
	    text-indent: .15em;
	    line-height: 1; 
	}

	input[type="radio"]:checked + label::before {
	    background-color: #01cd78;
	    background-clip: content-box;
	    padding: .2em;
	}	
	input[type="radio"] {
	    position: absolute;
	    clip: rect(0, 0, 0, 0);
	}	

	#allmap {
		height: 500px;
		width: 100%;
	}
	
	#r-result {
		width: 100%;
		font-size: 14px;
	}
	</style>	
	</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                        <div class="form-inline">
							<form name = "form1" id = "update_area_gift"  enctype='multipart/form-data'>
									<input type = "hidden" class = "addInput" name = "id" value = "${ag.id }">
								<div class="form-item">
									<label class="label-text">名称：</label>
									<input type = "text" class = "addInput" name = "name" value = "${ag.name }"><br/><br/>
								</div>
								<div class="form-item">
									<label  class="label-text">所属区域：</label>
									<select name = "areaId" id="roleList">
										<option value = "">全部区域</option>
										<c:forEach items = "${aList }" var = "e">
											<option value = "${e.id}" <c:if test="${ag.areaId == e.id }">selected</c:if>>${e.name }</option>
										</c:forEach>
									</select><br/><br/>
								</div>
								<div class="form-item">
									<label class="label-text">简介：</label>
									<input type = "text" class = "addInput" name = "info" value = "${ag.info }"><br/><br/>
								</div>
								<div class="form-item">
									<label class="label-text">链接：</label>
									<input type = "text" class = "addInput" name = "link" value = "${ag.link }"><br/><br/>
								</div>	
								<div class="form-item" style='width:100%;display:table;'>
									<label  class="label-text" style='float:left'>图片：</label>
									<div style='width:80%;displat:table;float:left'>
										<img alt="" src="${ag.imageUrl }" style='height:150px;margin-left:24px'>
									</div>
									<div style='width:calc(100% - 54px);display:block;margin:10px 0 10px 54px;'>
										<input type='file' name='imageUrls' onchange="imageChange(this);" accept=".png,.jpg,.jpeg" >
									 	&nbsp;&nbsp;不能超过2M
									</div>
									
								</div>	
								<button type = "submit" class="btn btn-primary">确定</button>
						    </form>
						</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>

    
    <script type="text/javascript">
 
    $().ready(function () {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#update_area_gift").validate({
            rules: {
            	name: {//姓名
                    required: true,
    				maxlength: 20
                },
                info: {//地址
                    required: true,
    				maxlength: 200
                },
                link:{
                    required: true,
                	url:true
                }
            },
            messages: {
            	name:{
            		required:icon + "请填写名称",
            		maxlength:icon + "最大长度为20"
            	},
                info:{
            		required:icon + "请输入地址",
            		maxlength:icon + "最大长度为200"
            	},
            	link: {
            		required:icon + "请输入地址",
             		url:icon + "请输入正确网址",
            	}
                
            },
    		submitHandler: function(form) {
    			updateArNavigation();
    		}
        });
    });
 	function cancel(){
 		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
 	}
	 function ValidateValue(textbox)
     {
          var IllegalString = "\`~@#;,.!#$%^&*()+{}|\\:\"<>?-=/,\' []";
          var textboxvalue = textbox.value;
          var index = textboxvalue.length - 1;
          
          var s = textbox.value.charAt(index);
          
          if(IllegalString.indexOf(s)>=0)
          {
             s = textboxvalue.substring(0,index);
             textbox.value = s;
          }
     }

	//添加或修改
	function updateArNavigation(){	
		var formData = new FormData($( "#update_area_gift" )[0]);  
		$.ajax({
			processData: false,
			contentType: false,
    		url:"${pageContext.request.contextPath }/admin/areaGift/update",
    		data:formData,
    		type:"post",
    		success:function(data){
    			if(data.code == 0){
					layer.msg(data.message,{icon:1});
					setTimeout('cancel()',1000);
    			}else {
					layer.msg(data.message,{icon:0});
    			}
    		}
    	});
	}
	
	</script>
</html>
